//package com.greenwiki.camera;
//
//
//
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//
//import android.app.Activity;
//import android.hardware.Camera;
//import android.hardware.Camera.PictureCallback;
//import android.hardware.Camera.ShutterCallback;
//import android.os.Bundle;
//import android.util.Log;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.FrameLayout;
//
//import com.greenwiki.R;
//
//public class GeneralCamera extends Activity {
//
//	private static final String TAG = GeneralCamera.class.getSimpleName();
//
//	private GeneralPreview preview;
//	private Camera mCamera;
//	private Button mSnapshot;
//
//	/* (non-Javadoc)
//	 * @see android.app.Activity#onCreate(android.os.Bundle)
//	 */
//	@Override
//	protected void onCreate(Bundle savedInstanceState) {
//		// TODO Auto-generated method stub
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.general_camera);
//
//		preview = new GeneralPreview(this);
//		FrameLayout flPreview = ((FrameLayout) findViewById(R.id.preview));
//		flPreview.addView(preview);
//		
//		mSnapshot = (Button) findViewById(R.id.buttonSnapshot);
//		mSnapshot.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				Log.d(TAG, "mSnapshot got click");
//				//preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
//			}
//			
//		});
//		
//		Log.d(TAG, "onCreate has been called");
//	}
//	
//	ShutterCallback shutterCallback = new ShutterCallback() {
//
//		@Override
//		public void onShutter() {
//			// TODO Auto-generated method stub
//			Log.d(TAG, "onShutter has been called");
//		}
//		
//	};
//	
//	PictureCallback rawCallback = new PictureCallback() {
//
//		@Override
//		public void onPictureTaken(byte[] data, Camera camera) {
//			// TODO Auto-generated method stub
//			Log.d(TAG, "onPictureTaken - raw has been called");
//		}
//		
//	};
//	
//	PictureCallback jpegCallback = new PictureCallback() {
//		public void onPictureTaken(byte[] data, Camera camera) {
//			FileOutputStream fos = null;
//			try {
//				fos = new FileOutputStream(String.format(
//						"/sdcard/%d-%d-%d.jpg", System.currentTimeMillis(), 0, 0));
//				fos.write(data);
//				fos.close();
//				Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
//			} catch (FileNotFoundException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			} finally {
//				
//			}
//			Log.d(TAG, "onPictureTaken - jpeg");
//		}
//	};
//	
//}

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.greenwiki.camera;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;

import com.greenwiki.R;



// ----------------------------------------------------------------------

public class GeneralCamera extends Activity {
	private static final String TAG = GeneralCamera.class.getSimpleName();
	
    private GeneralPreview mPreview;
    private Button mSnapshot;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Hide the window title.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN );
		setContentView(R.layout.general_camera);

        
		mSnapshot = (Button) findViewById(R.id.buttonSnapshot);
		mSnapshot.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mPreview.mCamera.takePicture(shutter, raw, jpeg);
			}
			
		});
		
		// Create a FrameLayout container that will hold a SurfaceView,
		mPreview = new GeneralPreview(this);
        FrameLayout flPreview = ((FrameLayout) findViewById(R.id.previewStage));
        flPreview.addView(mPreview);
        
        
        
        mPreview.invalidate();
        
    }
    
    private ShutterCallback shutter = new ShutterCallback() {

		@Override
		public void onShutter() {
			// TODO Auto-generated method stub
			
		}
    	
    };
    
    private PictureCallback raw = new PictureCallback() {

		@Override
		public void onPictureTaken(byte[] data, Camera camera) {
			// TODO Auto-generated method stub
			Log.d(TAG, "onPictureTaken - raw has been called");
		}
    	
    };
    
    private PictureCallback jpeg = new PictureCallback() {

		@Override
		public void onPictureTaken(byte[] data, Camera camera) {
			// TODO Auto-generated method stub
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream(String.format("/sdcard/%d-%d-%d.jpg", System.currentTimeMillis(), 0, 0));
				fos.write(data);
				fos.close();
				Log.d(TAG, "onPictureTaken - wrote byte: " + data.length);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				
			}
			Log.d(TAG, "onPictureTaken - jpeg has been called");
		}
    	
    };
}
